﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ED_Nivelacion.Datos;

namespace ED_Nivelacion.Negocios
{
    public class Actor_C
    {
        ED_NivelacionEntities _objEntity = new ED_NivelacionEntities();

        public List<Actor> ObtenerActor()
        {
            List<Actor> ListaActor = new List<Actor>();
            try
            {

                foreach (var item in _objEntity.SP_ConsultarActor())
                {
                    ListaActor.Add(new Actor { idActor = item.idActor, ActorTipo = item.Actor });
                }

                return ListaActor;
            }
            catch (Exception)
            {
                return ListaActor;
            }
        }

        public List<Actor> FiltrarActor(int _idActor)
        {
            List<Actor> ListaActor = new List<Actor>();

            try
            {

                var item = _objEntity.SP_ConsultarActor().Where(c => c.idActor == _idActor).FirstOrDefault();

                ListaActor.Add(new Actor { ActorTipo = item.Actor });


                return ListaActor;
            }
            catch (Exception)
            {
                return ListaActor;
            }
        }

        public string Agregar(Actor _obj)
        {
         string msm = "OK";
            try
            {
                _objEntity.SP_InsertarActor(_obj.ActorTipo); 
            }
            catch (Exception)
            {

                msm = "Error al Ingresar";
            }

            return msm;
        
        }

        public string Editar(Actor _obj)
        {
            string msm = "OK";
            try
            {
                _objEntity.SP_ActualizarActor(_obj.idActor,_obj.ActorTipo); 
            }
            catch (Exception)
            {

                msm = "Error al actualizar";
            }

            return msm;
        }

        public string Eliminar(int _idActor) 
        { 
        string msm = "OK";
            try
            {
                _objEntity.SP_EliminarActor(_idActor); 
            }
            catch (Exception)
            {

                msm = "Error al Eliminar";
            }

            return msm;
        }
        
        }
    }

